<?php
namespace app\admin\controller;

use app\admin\Auth;
use Atlaxy\Controller;
use think\facade\Cache;
use think\facade\Session;

/**
 * 管理首页
 */
class Index extends Base
{
    
    /**
     * 数据概览
     * @auth true
     */
    public function index()
    {
        $this->fetch();
    }

    /**
     * 修改密码
     * @auth false
     */
    public function repass()
    {
        if($this->request->isGet()){
            $this->fetch();
        }else{
            $password = $this->request->post('password',null,'trim');
            if(!$password)$this->jsonFail('请输入新密码');
            $this->user->password = $password;
            if($this->user->save()){
                $this->jsonSucc();
            }else{
                $this->jsonFail('修改失败');
            }
        }
    }

    /**
     * 刷新缓存
     * @auth false
     */
    public function refresh()
    {
        if(Cache::set('authNodes',null)){
            $this->jsonSucc();
        }else{
            $this->jsonFail('刷新失败');
        }
    }

    public function logout()
    {
        Session::clear();
        $this->redirect('user/login');
    }
}